package com.amsp.oa.oademo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.amsp.oa.oademo.entity.EmployeeResignation;
import com.amsp.oa.oademo.service.EmployeeResignationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resignation")
@Api(tags = "员工离职管理")
@CrossOrigin
public class EmployeeResignationController {

    @Autowired
    private EmployeeResignationService employeeResignationService;

    @PostMapping("/save")
    @ApiOperation("保存或更新员工离职信息")
    public boolean saveOrUpdate(@RequestBody EmployeeResignation employeeResignation) {
        return employeeResignationService.saveOrUpdate(employeeResignation);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询员工离职信息")
    public IPage<EmployeeResignation> getPage(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("员工姓名") @RequestParam(required = false) String empName,
            @ApiParam("所在部门") @RequestParam(required = false) String empDepartment) {
        return employeeResignationService.getPage(current, size, empName, empDepartment);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询员工离职信息")
    public EmployeeResignation getById(@PathVariable Long id) {
        EmployeeResignation byId = employeeResignationService.getById(id);
        return byId;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除员工离职信息")
    public boolean removeById(@PathVariable Long id) {
        return employeeResignationService.removeById(id);
    }
}